﻿using System.Collections.Generic;
using System;
using CommunityToolkit.Mvvm;
using CommunityToolkit.Mvvm.ComponentModel;
using LiveCharts;

namespace WpfScrollChart
{
    internal class MainViewModel : ObservableObject
    {
        List<double> allPoints;
        List<string> allLabels;

        public MainViewModel()
        {
            // Generate sample data
            ChartValues = new ChartValues<double>();
            allPoints = new List<double>();
            Labels = new List<string>();
            allLabels = new List<string>();

            for (int i = 0; i < 1000; i++)
            {
                allPoints.Add(Math.Sin(i * Math.PI / 180)); // Sample data
                allLabels.Add(i.ToString()); // Labels
            }
            ScrollBarValue = 0;
            MaxScrollBarValue = allLabels.Count - 100; // Set maximum value of scroll bar
        }

        private int _scrollBarValue;
        private ChartValues<double> _chartValues;
        private List<string> _labels;

        public int ScrollBarValue
        {
            get { return _scrollBarValue; }
            set
            {
                _scrollBarValue = value;
                OnPropertyChanged("ScrollBarValue");
                UpdateChartData(value);
            }
        }

        public void UpdateChartData(int startIndex)
        {
            // Update chart values and labels based on the startIndex
            ChartValues.Clear();
            Labels.Clear();

            for (int i = startIndex; i < startIndex + 100; i++)
            {
                ChartValues.Add(allPoints[i]); // Sample data
                Labels.Add(allLabels[i]); // Labels
            }
        }

        public ChartValues<double> ChartValues
        {
            get { return _chartValues; }
            set { SetProperty(ref _chartValues, value); }
        }
        public List<string> Labels
        {
            get { return _labels; }
            set { SetProperty(ref _labels, value); }
        }
        public int MaxScrollBarValue { get; set; }
    }
}
